<template>
  <div style="height: calc(100vh)">
    <header>
      <!-- 登录前登陆后显示不同 -->
      <div class="profilPic">
        <img
          src="../assets/head.png"
          alt=""
          v-if="$store.state.isLogin == false"
        />
        <img
          :src="$store.state.userInfo.avatar"
          alt=""
          v-if="$store.state.isLogin == true"
          style="width: 64px"
        />
      </div>
      <router-link to="/login">
        <div class="toLogin" v-if="$store.state.isLogin == false">点击登录</div>
      </router-link>
      <div class="toLogin" v-if="$store.state.isLogin == true">
        {{ $store.state.userInfo.userName }}
      </div>
    </header>
    <div class="list" @click="seePer">
      查看个人信息<van-icon
        name="arrow"
        style="float: right; line-height: 50px"
      />
    </div>
    <div class="list" @click="resetPer">
      修改个人信息<van-icon
        name="arrow"
        style="float: right; line-height: 50px"
      />
    </div>
    <div class="list" @click="toCollect">
      我的收藏<van-icon name="arrow" style="float: right; line-height: 50px" />
    </div>
    <div class="list">
      历史记录<van-icon name="arrow" style="float: right; line-height: 50px" />
    </div>
    <div class="loginOut" v-if="$store.state.isLogin == true">
      <van-button
        type="default"
        @click="loginOut"
        style="margin-top: 30px; height: 40px; width: 100px"
        >退出登录</van-button
      >
    </div>
    <!-- 底部 -->
  </div>
</template>
<script>
import { logout } from "../api/api";
export default {
  methods: {
    loginOut() {
      //退出登录
      logout().then(() => {});
      this.$store.commit("changeInfo", {
        isLogin: false,
        userInfo: {},
      });
    },
    //察看个人信息
    seePer() {
      if (this.$store.state.isLogin) {
        this.$router.push("/layout/personalMsg");
      } else {
        this.$router.push("/login");
      }
    },
    //
    resetPer() {
      if (this.$store.state.isLogin) {
        this.$router.push("/layout/resetPerMsg");
      } else {
        this.$router.push("/login");
      }
    },
    toCollect() {
      if (this.$store.state.isLogin) {
        this.$router.push("/layout/collect");
      } else {
        this.$router.push("/login");
      }
    },
  },
};
</script>
<style lang="less" scoped>
* {
  margin: 0;
  padding: 0;
}
header {
  width: 100%;
  padding: 50px 0 20px 40px;
  border-bottom: 10px solid #eee;
  overflow: hidden;
  box-sizing: border-box;
  .profilPic {
    float: left;
    position: relative;
  }
  .toLogin {
    width: 70%;
    height: 110px;
    float: right;
    font-size: 20px;
    line-height: 57px;
    overflow: hidden;
  }
}
.list {
  width: 100%;
  height: 50px;
  padding: 5px 20px;
  line-height: 50px;
  box-sizing: border-box;
}
.loginOut {
  width: 100%;
  text-align: center;
  padding: 30px;
  box-sizing: border-box;
}
</style>